package com.hq.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hq.bean.Orderbiao;
import com.hq.bean.User;
import com.hq.service.OrderService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

@Controller
public class OrderController {
    @Resource
    private OrderService orderService;
    @RequestMapping("list.do")
    public String list(@RequestParam(value = "cpage",defaultValue = "1")Integer cpage,
                       String dingdanbianhao,//模糊
                       String zhidanren, //模糊
                       String cangku, //模糊
                       String dinghuoren, //模糊
                       String jiaohuofangshi, //模糊
                       String wuliudanhao, //模糊
                       String jiaohuodidian, //模糊
                       String xiadanshijianD, //范围
                       String xiadanshijianX, //范围
                       Integer kuweiD, //范围
                       Integer kuweiX, //范围
                       Integer zongjineD, //范围
                       Integer zongjineX, //范围
                       Integer zherangjineD, //范围
                       Integer zherangjineX, //范围
                       Integer fujianchengbenD, //范围
                       Integer fujianchengbenX,  //范围
                       Model model
    ) {
        HashMap map = new HashMap();
        map.put("dingdanbianhao", dingdanbianhao);
        map.put("zhidanren", zhidanren);
        map.put("cangku", cangku);
        map.put("dinghuoren", dinghuoren);
        map.put("jiaohuofangshi", jiaohuofangshi);
        map.put("wuliudanhao", wuliudanhao);
        map.put("jiaohuodidian", jiaohuodidian);
        map.put("xiadanshijianD", xiadanshijianD);
        map.put("xiadanshijianX", xiadanshijianX);
        map.put("kuweiD", kuweiD);
        map.put("kuweiX", kuweiX);
        map.put("zongjineD", zongjineD);
        map.put("zongjineX", zongjineX);
        map.put("zherangjineD", zherangjineD);
        map.put("zherangjineX", zherangjineX);
        map.put("fujianchengbenD", fujianchengbenD);
        map.put("fujianchengbenX", fujianchengbenX);
        PageHelper.startPage(cpage,2);
        List list = orderService.list(map);
        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("map", map);
        return "list";
    }
    @RequestMapping("toadd.do")
    public String toadd(){
        return "add";
    }
    @RequestMapping("add.do")
    @ResponseBody
    public Object add(Orderbiao orderbiao){
        int add = orderService.add(orderbiao);
        return add;
    }
    @RequestMapping("login.do")
    public Object login(User user, HttpSession session){
        User login = orderService.login(user);
        if (login!=null){
            session.setAttribute("user",user);
            return "redirect:list.do";
        }else {
            return "redirect:index.jsp";
        }
    }
    @RequestMapping("list2.do")
    public String list2(Model model) {
        HashMap map = new HashMap();
        List list = orderService.list(map);
        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("map", map);
        return "list";
    }
    @RequestMapping("list3.do")
    public String list3(Model model) {
        HashMap map = new HashMap();
        List list = orderService.list(map);
        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("map", map);
        return "list";
    }
}